import 'package:flutter/material.dart';
import 'package:flutter_oldman_health/api/constant.dart';
import 'package:flutter_oldman_health/widget/common_container.dart';

// @deprecated
class MessageListPage extends StatefulWidget {
  @override
  MessageListPageState createState() {
    return MessageListPageState();
  }
}

class MessageListPageState extends State<MessageListPage> {
  @override
  Widget build(BuildContext context) {
    return Container(
        color: Constant.backgroundColor,
        padding: EdgeInsets.fromLTRB(16, 0, 16, 0),
        child: ListView(children: _getListData()));
  }

  List data = [
    {
      "member": "张三",
      "relationship": "father",
      "msg": "你妈喊你回家吃饭",
      "data": "09月10日",
      "time": "1:33",
      "state": 1
    },
    {
      "member": "张四",
      "relationship": "father",
      "msg": "王者荣耀,不见不散",
      "data": "09月10日",
      "time": "1:33",
      "state": 0
    },
    {
      "member": "张三2",
      "relationship": "father",
      "msg": "你妈喊你回家吃饭",
      "data": "09月10日",
      "time": "1:33",
      "state": 1
    },
    {
      "member": "张四3",
      "relationship": "father",
      "msg": "王者荣耀,不见不散",
      "data": "09月10日",
      "time": "1:33",
      "state": 0
    },
    {
      "member": "张三",
      "relationship": "father",
      "msg": "你妈喊你回家吃饭",
      "data": "09月10日",
      "time": "1:33",
      "state": 1
    },
    {
      "member": "张四",
      "relationship": "father",
      "msg": "王者荣耀,不见不散",
      "data": "09月10日",
      "time": "1:33",
      "state": 0
    }
  ];

  List<Widget> _getListData() {
    List<Widget> items = [_getTitle()];
    var tempList = data.map((e) => CommonContainer(
        Column(
          children: [
            Text(
                e["data"] +
                    " " +
                    e["time"] +
                    "\n" +
                    e["msg"] +
                    "\n来自" +
                    e["relationship"],
                textAlign: TextAlign.center,
                style: TextStyle(
                    fontSize: 19,
                    color:
                        e["state"] == 0 ? Colors.black54 : Color(0xFFAAAAAA))),
            Padding(
                padding: EdgeInsets.only(top: 16),
                child: Text(e["state"] == 1 ? "已完成" : "未完成",
                    style: TextStyle(
                        fontSize: 12,
                        color: e["state"] == 0
                            ? Colors.black54
                            : Color(0xFFAAAAAA))))
            // Text(e["msg"],style: TextStyle(fontSize: 18,color: Color(0xFFAAAAAA))),
          ],
        ),
        margin:EdgeInsets.fromLTRB(0, 0, 0, 12),
        padding:EdgeInsets.all(16)));
    items.addAll(tempList.toList());
    return items;
  }

  Widget _getTitle([String title = "消息"]) {
    return  Container(
      color: Constant.appbarColor,
          padding: EdgeInsets.fromLTRB(8, 10, 8, 16),
          child: Text(title,
              textAlign: TextAlign.center,
              style: TextStyle(fontSize: 19, color: Colors.black87)),
        );
  }
}
